import QtQuick 2.2
import "../mainmenu"

Rectangle {
    property int rowCount: 6
    property int columnCount: 2
    property int columnspacing: 0
    property int rowspacing: 0

    property int textHAlign: 1
    property int textVAlign: 1

    property int itemWidth: (width- columnspacing*(columnCount + 1))/columnCount
    property int itemHeight: (height - rowspacing*(rowCount +1))/rowCount

    property int itemCount: 0

    //可往下翻页的标志
    property bool nextFlag: false

    //可网上翻页的标志
    property bool previousFlag: false

    property var textnameList: new Array

    property string itemBorderColor: "white"
    property string framBorderColor: "white"

    property int fontSize: 18

    function resetText()
    {
        for(var i=0 ; i< rowCount*columnCount; i++)
            grid.children[i].textname = (i + itemCount) < textnameList.length ? textnameList[i + itemCount]: ""
    }

    function getItem(index)
    {
        return grid.children[index]
    }

    function getItemfromPoint(x, y)
    {
        return grid.childAt(x, y).textname;
    }

    border.color: framBorderColor
    border.width: 1

    Grid{
        id: grid
        columns: columnCount; columnSpacing: columnspacing
        rows: rowCount; rowSpacing: rowspacing
        horizontalItemAlignment: Grid.AlignHCenter; verticalItemAlignment: Grid.AlignVCenter

        Repeater{
            model: rowCount*columnCount
            InstructItem{
                textname: (index + itemCount) < textnameList.length ? textnameList[index + itemCount]: ""
                bordercolor: itemBorderColor
                borderwidth: 1
                width: itemWidth
                height: itemHeight
//                width: (parent.width- columnspacing*(columnCount + 1))/columnCount
//                height: (parent.height - rowspacing*(rowCount +1))/rowCount
                textVLocate: textVAlign; textHLocate: textHAlign
                fontsize: fontSize
            }
        }
        anchors.fill: parent
        anchors.leftMargin: columnspacing; anchors.topMargin: rowspacing
    }
}
